<div id="header">
  <div id="topnav">
  <%if CheckLogin() then%>
    <label id="user"><a id="changepws" href="#"><%=session("sFullName")%></a></label>
    <a id="logout" href="#">，退出</a>
  <%
    Set rs_mytodo = Server.CreateObject("ADODB.Recordset")
    sql = "SELECT count(*) as mytodos FROM todo where userid="&session("iID")&" and active_date=date() and deleted=false"
    rs_mytodo.Open sql,conn,1,1
    if not rs_mytodo.eof then
        mytodos=rs_mytodo("mytodos")
    end if
    rs_mytodo.close
    set rs_mytodo=nothing
  %>
  
  <div>我今天有 <%=mytodos%> 个任务</div>
  <%else%>
    <a id="login" href="#">登录</a>
  <%end if%>
  
  </div>
  <h1>宁波诗鸿报关代理有限公司</h1>
</div>
<div id="dv_changepws" title="修改密码">
  <form id="fm_changepws" method="post" class="yform full" role="application">
    <div class="type-text">
      <label for="old_password">原密码*</label>
      <input name="old_password" id="old_password" type="password" maxlength="10" class="validate[required,minSize[6],maxSize[10]]" />
    </div>
    <div class="type-text">
      <label for="new_password">新密码*</label>
      <input name="new_password" id="new_password" type="password" maxlength="10" class="validate[required,minSize[6],maxSize[10],custom[onlyPassword]]" />
    </div>
    <div class="type-text">
      <label for="confirm_password">确认密码*</label>
      <input name="confirm_password" id="confirm_password" type="password" maxlength="10" class="validate[required,minSize[6],maxSize[10],custom[onlyPassword]]" />
    </div>
  </form>
</div>
<div id="dv_login" title="登录界面">
  <form id="fm_login" method="post" class="yform full" role="application">
    <div class="type-text">
      <label for="login_username">用户名*</label>
      <input name="login_username" id="login_username" type="text" maxlength="10" class="validate[required,minSize[3],maxSize[10]]" />
    </div>
    <div class="type-text">
      <label for="login_password">密码*</label>
      <input name="login_password" id="login_password" type="password" maxlength="10" class="validate[required,minSize[6],maxSize[10]]" />
    </div>
  </form>
</div>
<div id="dv_todo" title="任务界面">
  <form id="fm_todo" method="post" class="yform full" role="application">
    <div class="type-text">
      <label for="todo_title">任务标题*</label>
      <input name="todo_title" id="todo_title" type="text" class="validate[required]" />
      <input name="todo_id" id="todo_id" type="hidden" value="0" />
    </div>
    <div class="type-text">
      <label for="todo_active">提醒日期</label>
      <input name="todo_active" id="todo_active" type="text" size="10" readonly="readonly" />
    </div>
    <div class="type-check">
        <input id="todo_star" name="todo_star" type="checkbox" />
        <label for="todo_star">重要</label>
    </div>

    <div class="type-text">
        <label for="todo_content">任务内容</label>
        <textarea name="todo_content" id="todo_content" rows="4"></textarea>
    </div>
  </form>
</div>

<script type="text/javascript">
  $(function() {
    function checkchangepws(o,n,c){
      if(o==""){
        r=1
      }else if(n==""|c==""){
        r=2
      }else if(o.length<6||n.length<6||c.length<6){
        r=3
      }else if(n!=c){
        r=4
      }else if(o==n){
        return 5
      }else if(!checkpws(n)){
        r=6
      }else{
        r=0
      }
      return r
    }
    $("#login").click(function(){
      $("#dv_login").dialog("open");
    });
    $("#changepws").click(function(){
      $("#dv_changepws").dialog("open");
    })
    $("#dv_changepws").dialog({
      autoOpen: false,
      minHeight:200,
      modal: true,
      buttons: {
        "确定": function() {
          if($("#fm_changepws").validationEngine('validate')){
            $.post("changepws.asp",{action:"确定",old_password:$.md5($("#old_password").val()),new_password:$.md5($("#new_password").val()),confirm_password:$.md5($("#confirm_password").val()),checkchangepws:checkchangepws($("#old_password").val(),$("#new_password").val(),$("#confirm_password").val())},function(data){
              if(data){
                alert(data.sInfo);
                if(data.bStatus){
                  if($("#url").val()){
                    location.href=$("#url").val();
                  }else{
                    location.href="index.asp";
                  }
                }
              }
            },"json");
          }
        },
        "取消": function() {
          $(this).dialog( "close" );
        }

      }
    });
    $("#dv_login").dialog({
      autoOpen: false,
      minHeight:200,
      modal: true,
      buttons: {
        "登录": function() {
          $.post("login.asp",{action:"登录",username:$("#login_username").val(),password:$.md5($("#login_password").val()),checkpws:checkpws($("#login_password").val())},function(data){
            if(data.bStatus){
              if(data.bChangePws){
                alert(data.sInfo);
                location.href="index.asp";
              }else{
                if($("#url").val()){
                  location.href=$("#url").val();
                }else{
                  location.href="index.asp";
                }
              }
            }else{
              alert(data.sInfo);
            }
          },"json");
        },
        "取消": function() {
          $(this).dialog( "close" );
        }

      }
    });
    
    $("#create_cdtodo").click(function(){
      $("#fm_todo")[0].reset();
      $("#dv_todo").dialog("open");
    })
    $("#todo_active").datepicker({ minDate: 0 });    
    $("#dv_todo").dialog({
      autoOpen: false,
      minHeight:200,
      //width:400,
      modal: true,
      position: { my: "center center", at: "center center" },
      buttons: {
        "保存": function() {
        if($("#fm_todo").validationEngine('validate')){
          $.post("json_todo.asp?action=保存&cd="+$("#id").val()+"&"+$("#fm_todo").serialize(),function(data){
            alert(data.sInfo);
            if(data.bStatus){
                //$("#dv_todo").dialog( "close" );
                location.reload();
            }
          },"json");
          }
        },
        "取消": function() {
          $(this).dialog( "close" );
        }

      }
    });

    
    $("#logout").click(function(){
      $.post("login.asp",{action:"退出"},function(data){
        if(data.bStatus){
          location.href="index.asp";
        }
      },"json");
    });

  });
</script>
